package com.luoxue.execsql.rest.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.luoxue.execsql.common.contact.ExecSqlContact;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("")
public class IndexController {

    @GetMapping
    public Mono<String> index() {
        return Mono.just("hello world");
    }

    @GetMapping("/getAsyncRoutes")
    public Mono<JSONObject> getAsyncRoutes(@RequestParam("name") String name) {
        String authority;
        if (name != null && name.equals("admin")) {
            authority = "v-admin";
        } else {
            authority = "v-test";
        }
//        String str = String.format("[{\"path\":\"/permission\",\"redirect\":\"/permission/page/index\",\"meta\":{\"title\":\"menus.permission\",\"icon\":\"lollipop\",\"i18n\":true,\"rank\":7},\"children\":[{\"path\":\"/permission/page/index\",\"name\":\"permissionPage\",\"meta\":{\"title\":\"menus.permissionPage\",\"i18n\":true}},{\"path\":\"/permission/button/index\",\"name\":\"permissionButton\",\"meta\":{\"title\":\"menus.permissionButton\",\"i18n\":true,\"authority\":[\"%s\"]}}]}]",authority).replaceAll("\n","");
        String str = "[]";
        str = String.format("{\"code\":0,\"info\":%s}", str);
        JSONObject jsonObject = JSON.parseObject(str);
        return Mono.just(jsonObject);
    }

}
